package com.xukehong.demo.collect;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.junit.Test;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * xkh on 2020/4/7
 */
public class Collect {


    String JRTT = "https://www.toutiao.com";

    String 科技 = "https://www.toutiao.com/api/pc/feed/?category=news_tech&utm_source=toutiao&widen=1&max_behot_time=0&max_behot_time_tmp=0&tadrequire=true&as=A195BEE8CCC287D&cp=5E8CC248776D6E1&_signature=VDl3LAAgEBDExvWH5e32blQ4NjAAAq2Z0rUKcNfEpHmxwOv6xuciV2gItByy8wjo4CBZdP9VedhHCjBK.uhVph03tNdZH0LrzwjUXY.ng6z5UMNZLPVQqvaH5y3rlxtSv3I";
    String 体育 = "https://www.toutiao.com/api/pc/feed/?category=news_sports&utm_source=toutiao&widen=1&max_behot_time=0&max_behot_time_tmp=0&tadrequire=true&as=A1954E682C43E24&cp=5E8C93CE52B4CE1&_signature=B0yDQgAgEBCXswHpAWIdkgdNwlAAFnGxw262Pj4.dh.cKtrb2zw0BEd-BifcYXe7u64Y3j3C7IzvAxRgvPqvhCvUiA1PhaZWtt2-Ilxp6clSQML-ku7vFE8xz9bJGvZwi1J";

    @Test
    public void http() throws IOException {
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder()
                .url(体育)
                .method("GET", null)
                .addHeader("cookie", " __tasessionId=r5214rj931586243578320; csrftoken=f7e870feea808ab221a586a9acca2102; tt_webid=6812864235942610445; s_v_web_id=verify_k8pkgyla_vkxfmnKP_c5to_4gec_BakM_cBNTqh8vig0b; ttcid=9a608f4601f541bb90b95c3b747db22d19; tt_webid=6812864235942610445; SLARDAR_WEB_ID=084e947d-2d12-4d19-a51b-17ef05c7f4df; WEATHER_CITY=%E5%8C%97%E4%BA%AC; tt_scid=WEOTnJq9jw59huygHh.XN9XRNdarXErD6U36.RgdIK6omOZFgIpgjJz-WYSUIe3Fefa1")
                .addHeader("Cookie", "tt_webid=6812864235942610445")
                .build();
        Response response = client.newCall(request).execute();
        String content = String.valueOf(JSON.parse(response.body().string()));
        JSONObject jsonObject = JSONObject.parseObject(content);
        System.out.println("数据1==============" + jsonObject);
        JSONArray jsonArray = jsonObject.getJSONArray("data");
        jsonArray.stream().forEach(json -> {
            JSONObject data = JSONObject.parseObject(json.toString());
            //文章地址
            String item_id = JRTT + "/a" + data.getString("item_id");
            System.out.println("文章地址:" + item_id);
            //标题图片
            String image_url = data.getString("middle_image");
            System.out.println("标题图片:" + image_url);
            //标题
            String title = data.getString("title");
            System.out.println("标题:" + title);
            //作者地址
            String media_url = JRTT + data.getString("media_url");
            System.out.println("作者地址:" + media_url);
            //作者名字
            String source = data.getString("source");
            System.out.println("作者名字:" + source);
            //文档描述
            String mark = data.getString("abstract");
            System.out.println("文档描述:" + mark + "\n");
            //评论数
            String comments_count = data.getString("comments_count");
            System.out.println("评论数:" + comments_count + "\n");
        });
    }


    //北京28
    private String cbUrl1 = "http://www.999pe.com/Home/GetNewPCBJKL8?_=" + System.currentTimeMillis();
    //加拿大28
    private String cbUrl2 = "http://www.999pe.com/Home/GetNewCakeNo?_=1586254711653";
    //北京赛车
    private String cbUrl3 = "http://www.999pe.com/Home/GetNewPK10?_=1586254678656";
    //幸运飞艇
    private String cbUrl4 = "http://www.999pe.com/Home/GetNewMlaft?_=1586254810661";
    //六合彩
    private String cbUrl5 = "http://www.999pe.com/Home/GetNewSix?_=1586254676653";


    @Test
    public void cb() throws IOException {
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder()
                .url(cbUrl2)
                .method("GET", null)
                .build();
        Response response = client.newCall(request).execute();
        JSONArray jsonArray = JSONArray.parseArray(response.body().string());
        jsonArray.stream().forEach(json -> {
            System.out.println(json);
        });
    }


    /**
     * 1122开奖网
     */
    //极速赛车
    private String cbUrl1122_jssc = "https://aappii.1122xxx.com/lottery-client-api/races/min/10002?issue=0";
    //幸运飞艇
    private String cbUrl1122_xyft = "https://aappii.1122xxx.com/lottery-client-api/races/min/10003?issue=0";
    //澳洲幸运10
    private String cbUrl1122_azxy10 = "https://aappii.1122xxx.com/lottery-client-api/races/min/10005?issue=0";
    //极速飞艇
    private String cbUrl1122_jsfq = "https://aappii.1122xxx.com/lottery-client-api/races/min/10004?issue=0";
    //11选5
    private String cbUrl1122_gd11x5 = "https://aappii.1122xxx.com/lottery-client-api/select5/min/10212?issue=0";

    @Test
    public void cb1122() throws IOException, ParseException {
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder()
                .url(cbUrl1122_gd11x5)
                .method("GET", null)
                .build();
        Response response = client.newCall(request).execute();
        JSONObject json = JSONObject.parseObject(response.body().string());
        JSONObject content = json.getJSONObject("content");
        String pdc = content.getString("pdc");
        //期数
        String pdi = content.getString("pdi");
        String dt = content.getString("dt");
        String ln = content.getString("ln");
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date endTime = format.parse(dt);
        String[] array = pdc.substring(1, pdc.length() - 1).split(",");
        System.out.println("期数:" + pdi);
        System.out.println("开奖时间:" + endTime.getTime());
        System.out.println("名字:" + ln);
        System.out.println(array[0]);

    }

    @Test
    public void pa() {

    }

}
